******************************
* Table 6: Heterogeneous treatment effects on health outcomes, by child attendance rate

************************
clear all
set trace off
set more off
clear
use Jehanabad_analytic_sample_hemoglobin
*label hemoglobin "child hemoglobin level"

global socio_cov_4_vari no_HHmembers years_schooling_father years_schooling_mother asset_index
global school_cov_4_vari total_enrollment class_size student_teacher_ratio


sort child_unique wave
gen att=total_attendance_2
replace att=total_attendance_2[_n+1] if wave==0

g post=wave
label var post "Post"  /* Post denotes endline survey */
g treat_post=treat*post
label var treat_post "Treat*post"
xtile child_att_tercile=att, nquantiles(3)


gen att_70=(att>0.7) if att!=.
gen att_80=(att>0.8) if att!=.
gen att_90=(att>0.9) if att!=.


**Panel A 
eststo clear
foreach var in hemoglobin any_an mild_an mod_sev_an{
xtset child_unique wave
eststo: xtreg `var' treat_post treat post $socio_cov_4_vari $school_cov_4_vari if att_70==1, fe cluster (school_id)
}
esttab using Table6_panel_A_70%.rtf, se(a3) keep(treat_post) varwidth(35) b(a3) star(* 0.10 ** 0.05 *** 0.01) replace ///
title(Table 6: Heterogeneous treatment effects on health outcomes, by child attendance rate)  mtitles("Hemoglobin (Hb g/dL)" "Any anemia" "Mild anemia" "Moderate or severe anemia" ) /// 
coeflabels(treat_post "Treat*post (70% attendance)") nonotes label ///


eststo clear
foreach var in hemoglobin any_an mild_an mod_sev_an{
xtset child_unique wave
eststo: xtreg `var' treat_post treat post $socio_cov_4_vari $school_cov_4_vari if att_80==1, fe cluster (school_id)
}
esttab using Table6_panel_A_70%.rtf, se(a3) keep(treat_post) varwidth(35) b(a3) star(* 0.10 ** 0.05 *** 0.01) append ///
mtitles("Hemoglobin (Hb g/dL)" "Any anemia" "Mild anemia" "Moderate or severe anemia" ) coeflabels(treat_post "Treat*post (80% attendance)") nonotes label

eststo clear
foreach var in hemoglobin any_an mild_an mod_sev_an{
xtset child_unique wave
eststo: xtreg `var' treat_post treat post $socio_cov_4_vari $school_cov_4_vari if att_90==1, fe cluster (school_id)
}
esttab using Table6_panel_A_70%.rtf, se(a3) keep(treat_post) varwidth(35) b(a3) star(* 0.10 ** 0.05 *** 0.01) append ///
mtitles("Hemoglobin (Hb g/dL)" "Any anemia" "Mild anemia" "Moderate or severe anemia" ) coeflabels(treat_post "Treat*post (90% attendance)") nonotes label ///




**********************************************************
**********************************************************
***Table 6, lets do child att by tercile instead of 70, 80, 90% cutoff
***********************************************************
**********************************************************

* Panel B, by child attendance terciles
eststo clear
foreach var in hemoglobin any_an mild_an mod_sev_an{
xtset child_unique wave
eststo: xtreg `var' treat_post treat post $socio_cov_4_vari $school_cov_4_vari if child_att_tercile==1, fe cluster (school_id)
}
esttab using Table6_panel_A_70%.rtf, se(a3) keep(treat_post) varwidth(35) b(a3) star(* 0.10 ** 0.05 *** 0.01) append ///
 mtitles("Hemoglobin (Hb g/dL)" "Any anemia" "Mild anemia" "Moderate or severe anemia" ) /// 
coeflabels(treat_post "Treat*post (Bottom tercile)") nonotes label 


eststo clear
foreach var in hemoglobin any_an mild_an mod_sev_an{
xtset child_unique wave
eststo: xtreg `var' treat_post treat post $socio_cov_4_vari $school_cov_4_vari if child_att_tercile==2, fe cluster (school_id)
}
esttab using Table6_panel_A_70%.rtf, se(a3) keep(treat_post) varwidth(35) b(a3) star(* 0.10 ** 0.05 *** 0.01) append ///
 mtitles("Hemoglobin (Hb g/dL)" "Any anemia" "Mild anemia" "Moderate or severe anemia" ) /// 
coeflabels(treat_post "Treat*post (Middle tercile)") nonotes label 

eststo clear
foreach var in hemoglobin any_an mild_an mod_sev_an{
xtset child_unique wave
eststo: xtreg `var' treat_post treat post $socio_cov_4_vari $school_cov_4_vari if child_att_tercile==3, fe cluster (school_id)
}
esttab using Table6_panel_A_70%.rtf, se(a3) keep(treat_post) varwidth(35) b(a3) star(* 0.10 ** 0.05 *** 0.01) append ///
 mtitles("Hemoglobin (Hb g/dL)" "Any anemia" "Mild anemia" "Moderate or severe anemia" ) /// 
coeflabels(treat_post "Treat*post (Top tercile)") nonotes label ///
addnotes("Notes: Each cell reports DD coefficients from a separate regression. Standard errors, clustered at the school level," ///
"are reported in parentheses. All regressions include child fixed effects and time-variant household & school-level controls reported" ///
"in Table 4. Any anemia is defined as a hemoglobin value < 11.5 g/dl, mild anemia is defined as a hemoglobin value ≥ 11 & < 11.5" ///
"g/dl,moderate/severe anemia is defined as a hemoglobin value < 11 g/dl. *, **, *** denote significance at the 10%, 5%, and" ///
 "1% level,respectively.")


********************************************End of do file *******************


